import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { ExcutePlan, RecmInfo, RoundInfo } from "../ExecutePlan";
import { IMoneyStrategy } from "../IMoneyStrategy";
import { IPlan } from "../IExecutePlan";
import { NormalStepMoneyStrategy } from "./NormalStepMoneyStrategy";
import { WithRecmMoneyStrategy } from "./WithRecmMoneyStrategy";
import { FixedStrategy } from "../recmStrategy/FixedStrategy";


export class WisdomMoneyStrategyV91 implements IMoneyStrategy {
    subPlan: IPlan[];
    debugCompoenent: string = "WisdomMoneyStrategyV91Debug";
    strategyName: string;
    startIndex: number = -1;
    startLevel: number = 10000;
    protected _autoSwitch: boolean = false;
    public get autoSwitch(): boolean { return this._autoSwitch; }
    public set autoSwitch(value: boolean) { this._autoSwitch = value; }
    protected _subPlanSum: number = 0;
    public get subPlanSum() {
        return this._subPlanSum;
    }
    constructor(name?: string, autoSwitch?: boolean) {
        this.strategyName = name ?? "GroupMoneyStrategy" + (new Date()).getMilliseconds() + parseInt((Math.random() * 1000).toString());
        this.subPlan = [];
        this._autoSwitch = autoSwitch ? true : false;
        this.resetStrategy();
    }
    showMoney(): [EnumBjlResult, number] {
        throw new Error("Method not implemented.");
    }
    resetRecm() {
        this.subPlan.forEach(item => item.resetRecm());
    }
    resetStrategy(): void {
        let plan1 = new ExcutePlan();
        plan1.recmStrategy = [new FixedStrategy({ reverse: false })]
        plan1.moneyStrategy = [new NormalStepMoneyStrategy("方案一", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: false,
            resetLevel: 80,
        }, true)];
        plan1.toResult(new RoundInfo());

        let plan2 = new ExcutePlan();
        plan2.recmStrategy = [new FixedStrategy({ reverse: false })];
        plan2.moneyStrategy = [new NormalStepMoneyStrategy("方案二", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true)];
        plan2.toResult(new RoundInfo());

        var pgPlan1 = new ExcutePlan();
        pgPlan1.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan1.moneyStrategy = [new WithRecmMoneyStrategy("方案1", 1, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan1.toResult(new RoundInfo());
        var pgfPlan1 = new ExcutePlan();
        pgfPlan1.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan1.moneyStrategy = [new WithRecmMoneyStrategy("反跟投1", 1, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan1.toResult(new RoundInfo());

        var pgPlan2 = new ExcutePlan();
        pgPlan2.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan2.moneyStrategy = [new WithRecmMoneyStrategy("跟投2", 2, false, new NormalStepMoneyStrategy("", {
            startMoney: 10,
            baseMoney:10,
            addStep: -20,
            devideStep: 10,
            reverse: true,
            resetLevel: 800,
        }, true))];
        pgPlan2.toResult(new RoundInfo());
        var pgfPlan2 = new ExcutePlan();
        pgfPlan2.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan2.moneyStrategy = [new WithRecmMoneyStrategy("反跟投2", 2, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan2.toResult(new RoundInfo());


        var pgPlan3 = new ExcutePlan();
        pgPlan3.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan3.moneyStrategy = [new WithRecmMoneyStrategy("跟投3", 3, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan3.toResult(new RoundInfo());
        var pgfPlan3 = new ExcutePlan();
        pgfPlan3.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan3.moneyStrategy = [new WithRecmMoneyStrategy("反跟投3", 3, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan3.toResult(new RoundInfo());

        var pgPlan4 = new ExcutePlan();
        pgPlan4.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan4.moneyStrategy = [new WithRecmMoneyStrategy("跟投4", 4, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan4.toResult(new RoundInfo());
        var pgfPlan4 = new ExcutePlan();
        pgfPlan4.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan4.moneyStrategy = [new WithRecmMoneyStrategy("反跟投4", 4, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan4.toResult(new RoundInfo());

        var pgPlan5 = new ExcutePlan();
        pgPlan5.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan5.moneyStrategy = [new WithRecmMoneyStrategy("跟投5", 5, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan5.toResult(new RoundInfo());
        var pgfPlan5 = new ExcutePlan();
        pgfPlan5.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan5.moneyStrategy = [new WithRecmMoneyStrategy("反跟投5", 5, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan5.toResult(new RoundInfo());

        var pgPlan6 = new ExcutePlan();
        pgPlan6.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan6.moneyStrategy = [new WithRecmMoneyStrategy("跟投6", 6, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan6.toResult(new RoundInfo());
        var pgfPlan6 = new ExcutePlan();
        pgfPlan6.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan6.moneyStrategy = [new WithRecmMoneyStrategy("反跟投6", 6, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan6.toResult(new RoundInfo());

        var pgPlan7 = new ExcutePlan();
        pgPlan7.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan7.moneyStrategy = [new WithRecmMoneyStrategy("跟投7", 7, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan7.toResult(new RoundInfo());
        var pgfPlan7 = new ExcutePlan();
        pgfPlan7.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan7.moneyStrategy = [new WithRecmMoneyStrategy("反跟投7", 7, true, new NormalStepMoneyStrategy("", {
            startMoney: 10,
            baseMoney:10,
            addStep: -20,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan7.toResult(new RoundInfo());

        var pgPlan8 = new ExcutePlan();
        pgPlan8.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan8.moneyStrategy = [new WithRecmMoneyStrategy("跟投8", 8, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan8.toResult(new RoundInfo());
        var pgfPlan8 = new ExcutePlan();
        pgfPlan8.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan8.moneyStrategy = [new WithRecmMoneyStrategy("反跟投8", 8, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan8.toResult(new RoundInfo());

        var pgPlan9 = new ExcutePlan();
        pgPlan9.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan9.moneyStrategy = [new WithRecmMoneyStrategy("跟投9", 9, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan9.toResult(new RoundInfo());
        var pgfPlan9 = new ExcutePlan();
        pgfPlan9.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan9.moneyStrategy = [new WithRecmMoneyStrategy("反跟投9", 9, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan9.toResult(new RoundInfo());

        var pgPlan10 = new ExcutePlan();
        pgPlan10.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgPlan10.moneyStrategy = [new WithRecmMoneyStrategy("跟投10", 10, false, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgPlan10.toResult(new RoundInfo());
        var pgfPlan10 = new ExcutePlan();
        pgfPlan10.recmStrategy = [new FixedStrategy({ reverse: false })];
        pgfPlan10.moneyStrategy = [new WithRecmMoneyStrategy("反跟投10", 10, true, new NormalStepMoneyStrategy("", {
            baseMoney:10,
            startMoney: 10,
            addStep: -10,
            devideStep: 10,
            reverse: true,
            resetLevel: 80,
        }, true))];
        pgfPlan10.toResult(new RoundInfo());

        this.subPlan = [
            plan1, plan2,
            pgPlan1, pgfPlan1,
            pgPlan2, pgfPlan2,
            pgPlan3, pgfPlan3,
            pgPlan4, pgfPlan4,
            pgPlan5, pgfPlan5,
            pgPlan6, pgfPlan6,
            pgPlan7, pgfPlan7,
            pgPlan8, pgfPlan8,
            pgPlan9, pgfPlan9,
            pgPlan10, pgfPlan10,
        ];

    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let zm = 0;
        let xm = 0;
        let recmV = EnumBjlResult.U;
        let recmMoney = 0;
        let sumWin = 0;

        this.subPlan.forEach((pl, index) => {
            pl.setResult(roundInfo, pl.recmInfo, pl.multiple, pl.waterRate, pl.fuliRate);
            let userRecmV = pl.toResult(roundInfo);
            let newRoundInfo: RoundInfo = Object.assign({}, roundInfo, { userRecm: userRecmV });
            pl.userRecmInfo.recmV = userRecmV;

            let [rv, rm] = pl.toMoney(newRoundInfo, pl.recmInfo, userRecm, pl.baseMoney);
            pl.recmInfo.preBetCount = pl.recmInfo.betCount;
            pl.recmInfo.recmV = rv;
            pl.recmInfo.recmMoney = rm;
            let win = pl.recmInfo.summaryInfo.winMoney - pl.recmInfo.summaryInfo.failMoney;
            sumWin += win;
            if (rv != EnumBjlResult.U) {
                //pl.recmInfo.
                pl.recmInfo.betCount++;
            }

            if (this._autoSwitch) {
                if (pl.recmInfo.summaryInfo.winMoney > pl.recmInfo.summaryInfo.failMoney) {
                    if (pl.recmInfo.recmV == EnumBjlResult.Z) {
                        zm += pl.recmInfo.recmMoney;

                    }
                    else if (pl.recmInfo.recmV == EnumBjlResult.X) {
                        xm += pl.recmInfo.recmMoney;
                    }
                }

            }
            else {
                if (pl.recmInfo.recmV == EnumBjlResult.Z) {
                    zm += pl.recmInfo.recmMoney;

                }
                else if (pl.recmInfo.recmV == EnumBjlResult.X) {
                    xm += pl.recmInfo.recmMoney;
                }

            }

        });

        recmInfo.summaryInfo.stWin = sumWin;;
        if (zm > xm) {
            recmV = EnumBjlResult.Z;
            recmMoney = zm - xm;
        }
        else if (xm > zm) {
            recmV = EnumBjlResult.X;
            recmMoney = xm - zm;
        }
        else {
            recmV = EnumBjlResult.U;
        }

        this._subPlanSum = sumWin;
        recmInfo.summaryInfo.winCount
        return [recmV, recmMoney];
    }

    copyValue(valueObj: any): void {
        var obj = valueObj as WisdomMoneyStrategyV91;
        if (obj) {
            this.debugCompoenent = obj.debugCompoenent;
            this.startIndex = obj.startIndex;
            for (let i = 0; i < this.subPlan.length; i++) {
                this.subPlan[i].copyValue(obj.subPlan[i]);
            }
        }
    }
}